{include file="header.html"}
<div class="title tc ml-30 mr-10">
	<h2>{$name}预购信息选择</h2>
</div>
<div class="content px-20">
<form name="myForm" id="myForm" action="/index.php?act=price&st=query_result" method="post">
	<section id="step1">
		<table class="my-10">
		    <tbody>
		        <tr>
		            <td class="pl-20">产品材质</td>
		            <td class="pl-15">
		            	<select name="marerials" class="w-150" id="marerials">
                        {if $marerialsCount > 1}
                        <option value='0'>请选择</option>
                        {/if}

                        {foreach item=marerial from=$marerials}
                        <option value="{$marerial.basic_price_id}">{$marerial.marerial}</option>
                        {/foreach}

		            	</select>
					</td>
		        </tr>

                {foreach item=model_one from=$model}
                {if $model_one.select_all == 0}
                <tr>
                    <td class="pl-20">{$model_one.price_name}</td>
                </tr>
                <tr>
                    <td class="pl-20" colspan="2">
                        <div style="border-left: 1px solid #ccc;margin-left: 8px">
                    <table>
                        {foreach item=model_twos from=$model_one.child}
                        <tr>
                            <td class="pl-20"><div>{$model_twos.price_name}</div></td>
                            <td class="pl-15">
                                <select name="model_{$model_twos.product_price_id}" class="w-150" id="model_{$model_twos.product_price_id}">
                                    {if $model_twos.childCount > 1}

                                    {/if}
                                    <option value='0'>请选择</option>
                                    {foreach item=model_three from=$model_twos.child}
                                    <option value="{$model_three.product_price_id}">{$model_three.price_name}</option>
                                    {/foreach}
                                </select>
                            </td>
                        </tr>
                        {/foreach}
                    </table></div>
                    </td>
                </tr>

                {else}
                <tr>
                    <td class="pl-20">{$model_one.price_name}</td>
                    <td class="pl-15">
                        <select name="model_{$model_one.product_price_id}"   onchange="javascript:showtable('{$model_one.product_price_id}');" class="w-150" id="model_{$model_one.product_price_id}">
                            {if $model_one.childCount > 0}
                            {/if}
                            <option value='0'>请选择</option>
                            {foreach item=model_twos from=$model_one.child}
                            <option value="{$model_twos.product_price_id}">{$model_twos.price_name}</option>
                            {/foreach}
                        </select>
                    </td>
                </tr>

                <tr id="table_{$model_one.product_price_id}" style="display: none">
                    <td class="pl-20"></td>
                    <td class="pl-15">
                        {foreach item=model_twos from=$model_one.child}
                        {if $model_twos.childCount > 0}
                        <select name="model_{$model_twos.product_price_id}"  class = "hidden" style="display: none;" class="w-150" id="model_{$model_twos.product_price_id}">
                            {if $model_twos.childCount > 1}
                            <option value='0'>请选择</option>
                            {/if}
                            {foreach item=model_three from=$model_twos.child}
                            <option value="{$model_three.product_price_id}">{$model_three.price_name}</option>
                            {/foreach}
                        </select>
                        {/if}
                        {/foreach}
                    </td>
                </tr>



                {/if}
                {/foreach}


                {if $area_priceCount > 0}
		        <tr>
		            <td class="pl-20">销售区域</td>
		            <td class="pl-15">
                        <select name="area_price" class="w-150" id="area_price">
                            {if $area_priceCount > 1}
                            <option value="0">请选择</option>
                            {/if}
                            {foreach item=areaprice from=$area_price}
                            <option value="{$areaprice.area_price_id}">{$areaprice.area_name}</option>
                            {/foreach}
                        </select>
					</td>
		        </tr>
                {/if}

                {if $arr_transportCount > 0}

		        <tr>
		            <td class="pl-20">运输方式</td>
		            <td class="pl-15">
                        <select name="transport" class="w-150" id="transport">
                        {if $arr_transportCount > 1}
                        <option value='0'>请选择</option>
                        {/if}

                        {foreach item=transport from=$arr_transport}
                        <option value="{$transport.transport_tmp_id}">{$transport.tmp_name}</option>
                        {/foreach}
		            	</select>
					</td>
		        </tr>

		        <tr id="transport_type">
		            <td class="pl-20">收货地</td>
		            <td class="pl-15">
		            	<select name="transport_type" class="w-150" id="sel_transport_type">

                            {if $addListCount > 1 || $arr_transportCount > 1}
		            		<option value="0">请选择</option>
                            {/if}
                            {foreach item=list from=$addList}
                            <option value="{$list.id}">{$list.name}</option>
                            {/foreach}

		            	</select>
					</td>
		        </tr>


                {/if}
		        <tr>
		            <td class="pl-20">购买数量</td>
		            <td class="pl-15"><input id="number" name="number" type="tel" class="w-90" /> 吨</td>
		        </tr>
                <tr>
                    <td class="pl-20">其他费用</td>
                    <td class="pl-15"><input id="price" name="price" type="tel" value="0" class="w-90" /> 元/吨</td>
                </tr>
		    </tbody>
		</table>
		<p class="tc"><button id="btn_submit" class="btn w-150 h-40"  onclick="javascript:sub();" type="button"> 查询到货价  </button></p>
        <p class="tc" style="margin-top: 10px;"><font color='red' id='td_visit_no'></font></p>
	</section>
    <input type="hidden" value="{$id}" name="id" />
    <input type="hidden" value="{$name}" name="name" />
</form>
<script type="text/javascript">
$(function(){

	$("#transport").on("change",function(){
            var id = $("#transport").val();
			$.ajax({
				type:"GET",
				url:"/?act=price&st=get_transport_area",
				data:{"id":id},
				dataType:"json",
				timeout:15000,
				success:function(data) {
					if(typeof data.errCode != 'undefined') {
						if(data.errCode == '00') {
							var html = "";
							if(typeof data.items != 'undefined' && data.items != "") {
								var items = data.items;
								if(items.length > 1) {
									html = "<option value='0'>请选择</option>";
								}
								for(var key in items) {
									html += "<option value='"+items[key].id+"'>"+items[key].name+"</option>";
								}
							}
							$("#sel_transport_type").html(html);
						}
					}
				},
				error:function() {
					/* alert("网络繁忙，请稍后再试！");
					return false; */
				}
			});

	});
	
});

function showtable(id){
    var ids = $("#model_"+id).val();
    $("#table_"+id).find('select').hide();
    $("#table_"+id).find('select').addClass('hidden');
    if(ids == 0){
        $("#table_"+id).hide();
    }else{

        $("#model_"+ids).show();
        //判断输入框是否有2个以上选项
        if($("#model_"+ids).get(0).options.length > 1){
            $("#table_"+id).show();
        }else{
            $("#table_"+id).hide();
        }

        $("#model_"+ids).removeClass('hidden');
    }
}

function sub(){

    var $selects = $("select");
    var errCount = 0;
    for(var i=0;i<$selects.length;i++){
        var $select = $selects.eq(i);
        //console.log($select.hasClass('hidden'));
        if(!$select.hasClass('hidden')){
            //console.log($select.val());
            if($select.val() == 0 || $select.val()== '') {
                errCount ++;
            }
        }else{
            $select.val(0);
        }
    }
    if($('#number').val() == '' || $('#number').val() <=0 ){
        errCount ++;
    }
    if($('#price').val() == '' ){
        errCount ++;
    }

    if(errCount == 0) {
        $("#myForm").submit();
    }else{
        errMsg = "* 请选择预购信息！";
        $("#td_visit_no").html(errMsg).show();;
    }
    return false;
}
</script>
</div>
{include file="footer.html"}